home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 90 / CDMM_90_1.ISO / Cycling Manager 2 / CyclingManager2Demo.exe / Disk1 / data1.cab / Game / DataCM2 / scripts / elements / draggers.cnh < prev    next >
Encoding:
Text File  |  2002-05-10  |  3.9 KB  |  173 lines

  1. // Message
  2. message Drag(Gui_Component _pComponent,i32x _iDeltaX,i32x _iDeltaY);
  3.  
  4. // Dragger Data
  5. class Gui_dtDragger
  6. {
  7.     var boolx bMoving;
  8.     var i32x iX;
  9.     var i32x iY;
  10.  
  11.     var i32x iDeltaX;
  12.     var i32x iDeltaY;
  13.  
  14.     var i32x iAccuX;
  15.     var i32x iAccuY;
  16. };
  17.  
  18.  
  19. func i32x Dragger_OnMouseUp(i32x _iX,i32x _iY,i32x _iButton);
  20. func i32x Dragger_OnMouseDown(i32x _iX,i32x _iY,i32x _iButton);
  21. func i32x Dragger_OnMouseMove(i32x _iX,i32x _iY);
  22.  
  23. // Message handling interface
  24. interface Gui_iBitmapDragger
  25. {
  26.     // Gui System Messages
  27.     Dragger_OnMouseDown    MouseDown;
  28.     Dragger_OnMouseUp    MouseUp;
  29.     Dragger_OnMouseMove    MouseMove;
  30. }
  31.  
  32. func Gui_Component NewDragger(Menu_Material _pMaterial,i32x _iDeltaX,i32x _iDeltaY);
  33.  
  34. /*
  35.  *    Function        : Dragger initializer 
  36.  *    Parameters        : _pMaterial material pointer
  37.  */
  38. func Gui_Component NewDragger(Menu_Material _pMaterial,i32x _iDeltaX,i32x _iDeltaY)
  39. {
  40.     var Menu_Sprite sprite;
  41.     var Gui_Component container;
  42.     var Gui_dtDragger pdtDragger;
  43.     var f32x sx,sy;
  44.     var i32x iArea;
  45.  
  46.     // Create container with button interface
  47.     container = NewContainer(Gui_iBitmapDragger);
  48.  
  49.     // Create a sprite with material and area index e_GUI_State_Enabled
  50.     sprite = NewSprite2D(_pMaterial);
  51.     iArea = e_GUI_State_Enabled;
  52.     SetArea(sprite,iArea);
  53.  
  54.     // Get size of area of index e_GUI_State_Enabled
  55.     sx = GetAreaWidth(_pMaterial,iArea);
  56.     sy = GetAreaHeight(_pMaterial,iArea);
  57.  
  58.     // Strech container to area size
  59.     StretchTo(container,sx,sy);
  60.  
  61.     // Define default align left/top (quicker than zoom)
  62.     SetAlign(container,e_GUI_HAlign_Left,e_GUI_VAlign_Top);
  63.  
  64.     // Attach the sprite to this container
  65.     AttachSprite(container,sprite);
  66.  
  67.     // Tell Gui to clip this sprite to container size
  68.     Clip(container);
  69.  
  70.     pdtDragger = new Gui_dtDragger;
  71.     pdtDragger.bMoving = false;
  72.     pdtDragger.iX = 0;
  73.     pdtDragger.iY = 0;
  74.  
  75.     if(_iDeltaX>=1)
  76.         pdtDragger.iDeltaX=_iDeltaX;
  77.     else 
  78.         pdtDragger.iDeltaX=1;
  79.  
  80.     if(_iDeltaY>=1)
  81.         pdtDragger.iDeltaY=_iDeltaY;
  82.     else
  83.         pdtDragger.iDeltaY=1;
  84.     
  85.     pdtDragger.iAccuX=0;
  86.     pdtDragger.iAccuY=0;
  87.  
  88.     SetData(container,pdtDragger);
  89.  
  90.     // Change interface to dragger interface
  91.     SetInterface(container,Gui_iBitmapDragger);
  92.     
  93.     return container;
  94. }
  95.  
  96.  
  97. func i32x Dragger_OnMouseDown(i32x _iX,i32x _iY,i32x _iButton)
  98. {
  99.     var Gui_Component pthis;
  100.     var Gui_dtDragger pdtDragger;
  101.     
  102.     pthis =GetThis();
  103.     pdtDragger = GetData(pthis);
  104.     pdtDragger.bMoving=1;
  105.     pdtDragger.iX = _iX;
  106.     pdtDragger.iY = _iY;
  107.     pdtDragger.iAccuX=0;
  108.     pdtDragger.iAccuY=0;
  109. }
  110.  
  111. func i32x Dragger_OnMouseUp(i32x _iX,i32x _iY,i32x _iButton)
  112. {
  113.     var Gui_Component pthis;
  114.     var Gui_dtDragger pdtDragger;
  115.     
  116.     pthis =GetThis();
  117.     pdtDragger = GetData(pthis);
  118.     pdtDragger.bMoving=0;
  119.     pdtDragger.iAccuX=0;
  120.     pdtDragger.iAccuY=0;
  121. }
  122.  
  123. func i32x Dragger_OnMouseMove(i32x _iX,i32x _iY)
  124. {
  125.     var Gui_Component pthis;
  126.     var Gui_dtDragger pdtDragger;
  127.     
  128.     pthis =GetThis();
  129.     pdtDragger = GetData(pthis);
  130.  
  131.     if(pdtDragger.bMoving)
  132.     {
  133.         var i32x iDeltaX,iDeltaY,iMustDragParent;
  134.         var Gui_Component pparent; 
  135.  
  136.         iDeltaX=_iX-pdtDragger.iX;
  137.         iDeltaY=_iY-pdtDragger.iY;
  138.  
  139.         pdtDragger.iAccuX=pdtDragger.iAccuX+iDeltaX;
  140.         pdtDragger.iAccuY=pdtDragger.iAccuY+iDeltaY;
  141.  
  142.         pdtDragger.iX = _iX;
  143.         pdtDragger.iY = _iY;
  144.  
  145.  
  146.         iMustDragParent=0;
  147.         iDeltaX=0;
  148.         iDeltaY=0;
  149.  
  150.         if((pdtDragger.iAccuX>=pdtDragger.iDeltaX)||(pdtDragger.iAccuX<=-pdtDragger.iDeltaX))
  151.         {
  152.             iDeltaX=(pdtDragger.iAccuX/pdtDragger.iDeltaX)*pdtDragger.iDeltaX;
  153.             pdtDragger.iAccuX=pdtDragger.iAccuX-iDeltaX;
  154.             iMustDragParent=1;
  155.         }
  156.         if((pdtDragger.iAccuY>=pdtDragger.iDeltaY)||(pdtDragger.iAccuY<=-pdtDragger.iDeltaY))
  157.         {
  158.             iDeltaY=(pdtDragger.iAccuY/pdtDragger.iDeltaY)*pdtDragger.iDeltaY;
  159.             pdtDragger.iAccuY=pdtDragger.iAccuY-iDeltaY;
  160.             iMustDragParent=1;
  161.         }
  162.  
  163.         if(iMustDragParent)
  164.         {
  165.             pparent = GetParent(pthis);
  166.             pparent<<Drag(pthis,iDeltaX,iDeltaY);
  167.         }
  168.     }//if(pdtDragger.bMoving)
  169. }
  170.  
  171.  
  172.  
  173.